﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace 数据换算
{
    public class MillimetreConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            double millimetre;
            bool result = double.TryParse(value as string, out millimetre);
            if (!result)
                return null;

            return millimetre;
        }
    }

    public class MilConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            double mil;
            bool result = double.TryParse(value as string, out mil);
            if (!result)
                return null;
            return mil;
        }
    }
}
